package com.bee.tlweb.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.bee.tlweb.model.News;

/**
 * @author joelli
 *
 */
public class PortalService {
	
	public static List<News> list = new ArrayList<News>();
	static {
		News n1 = new News();
		n1.setContent("新闻1，车刮了，与公交车");
		n1.setNewsId(1);
		n1.setTitle("交通事故");
		n1.setType(News.GNENERAL_NEWS);
		n1.setUpdateDate(new Date());
		
		News n2 = new News();
		n2.setContent("新闻2，吃顿饺子");
		n2.setNewsId(2);
		n2.setTitle("午餐故事");
		n2.setType(News.GNENERAL_NEWS);
		n2.setUpdateDate(new Date());
		
		News n3 = new News();
		n3.setContent("如何连接闪电邮客户端");
		n3.setNewsId(3);
		n3.setTitle("闪电邮");
		n3.setType(News.HELP_NEWS);
		n3.setUpdateDate(new Date());
		
		News n4 = new News();
		n4.setContent("如何备份邮件指南，第一步");
		n4.setNewsId(4);
		n4.setTitle("备份邮件");
		n4.setType(News.HELP_NEWS);
		n4.setUpdateDate(new Date());
		
		list.add(n1);
		list.add(n2);
		list.add(n3);
		list.add(n4);
	
		
		
	}
	
	public List<News> getFocusNews(){
		return list.subList(0, 2);
	}
	
	public List<News> getNews(int type){
		 List<News> result = new ArrayList<News>();
		 for(News n:list){
			 if(n.getType()==type){
				 result.add(n);
			 }
		 }
		 return result ;
			 
	}
	
	public List<News> serchNews(String key){
		 List<News> result = new ArrayList<News>();
		 for(News n:list){
			if(n.getContent().indexOf(key)!=-1){
				result.add(n);
			}
		 }
		 return result ;
	}
	
	
}
